package stringdemo;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 字符串-》不是以\0结尾的
 * User: GaoBo
 * Date: 2021-05-23
 * Time: 10:47
 */
public class TestDemo {

    public static void main(String[] args) throws UnsupportedEncodingException {
        /*byte[] bytes = {97,98,99,100};
        String str = new String(bytes,1,3);
        System.out.println(str);*/


      /*  String str2 = "abcd";
        byte[] bytes1 = str2.getBytes();
        System.out.println(Arrays.toString(bytes1));*/

        String str2 = "高博";
        byte[] bytes1 = str2.getBytes("utf-8");
        System.out.println(Arrays.toString(bytes1));
    }

    public static boolean isNumber1(String str) {
        for (int i = 0;i < str.length();i++) {
            char ch = str.charAt(i);
            if(ch < '0' ||  ch >'9') {
                return false;
            }
        }
        return true;
    }

    public static boolean isNumber(String str) {
        char[] chars = str.toCharArray();

        for (int i = 0;i < chars.length;i++) {
            if(chars[i] < '0' ||  chars[i] >'9') {
                return false;
            }
        }
        return true;
    }

    public static void main11(String[] args) {
        String str = "123456";
        boolean flg = isNumber(str);
        System.out.println(flg);
    }

    public static void main10(String[] args) {
        char[] chs = {'h','e','l','l','o'};
        //chs.length
        String str3 = new String(chs,1,3);
        System.out.println(str3);

        String str = "hello" ;
        char ch = str.charAt(1);
        System.out.println(ch);

        char[] chars = str.toCharArray();
        System.out.println(Arrays.toString(chars));
    }

    public static void main9(String[] args) {
        String str = "hello" ;
        for(int x = 0; x < 1000; x++) {
            str += x ;
        }
        System.out.println(str);
    }
    public static void main8(String[] args) {
        String str = "hello" ;
        String strTmp = new String("hello");
        str = str + " world" ;
        str += "!!!" ;
        System.out.println(str);
    }

    public static void main7(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello").intern();

        System.out.println(str1 == str2);

    }

    public static void main6(String[] args) {
        String str = null;
        // 方式一
        //System.out.println(str.equals("Hello"));
        // 方式二
        System.out.println("Hello".equals(str));
    }

    public static void main5(String[] args) {
        String str = new String("Hello");
        // 方式一
        System.out.println(str.equals("Hello"));
        // 方式二
        System.out.println("Hello".equals(str));
    }

    public static void main4(String[] args) {
        String str1 = "hello";
        String str2 = str1;
        System.out.println(str1);
        System.out.println(str2);

        str1 = "gaobo";
        System.out.println(str1);
        System.out.println(str2);
    }

    public static void main3(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");
        System.out.println(str1 == str2);

        String str3 = "he"+"llo";//编译的时候这个地方相当于 String str3 = "hello";
        System.out.println(str1 == str3);

        String str4 = "he";
        String str5 = "llo";
        String str6 = str4+str5;
        System.out.println(str1 == str6);

        String str7 = "he"+new String("llo");
        System.out.println(str1 == str7);

    }

    public static void main2(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");

        System.out.println(str1 == str2);

        System.out.println(str1.equals(str2));
    }


    public static void main1(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");
        char[] chs = {'h','e','l','l','o'};
        String str3 = new String(chs);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }
}
